﻿using DevelopTool.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace DevelopTool.Bll.DesktopClockBlls
{
    public class DesktopClockBll
    {
        public void Start()
        {
            //延迟2秒后打开时钟
            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer
            {
                Interval = 2000,
                Enabled = true
            };
            timer.Tick += delegate (object sender,EventArgs e)
            {
                timer.Stop();//停止计时器

                if(Setting.DesktopClock.Screens.Count <= 0) return;

                List<Screen> screens = Screen.AllScreens.OrderBy(it => it.DeviceName).ToList();

                foreach(Screen screen in screens)
                {
                    if(!Setting.DesktopClock.Screens.Exists(it => it == screen.DeviceName)) continue;
                    if(System.Windows.Forms.Application.OpenForms.Cast<Form>().Any(it => it is ClockForm form && form.ScreenId == screen.DeviceName)) continue;

                    ClockForm clockForm = new ClockForm(screen)
                    {
                        ScreenId = screen.DeviceName
                    };
                    clockForm.Show();
                }                
            };
        }
    }
}
